package com.nf.health.app.activity.miansearch.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.utils.DensityUtil;

import java.util.LinkedList;

/**
 * Created by Jason on 2016/9/29.
 */
public class ListRightAreaSecondAdapter extends BaseAdapter {
    private LinkedList<String> list;
    private Context cnt;
    private LayoutInflater layoutInflater;
    /*** 当前点击的二级条目 *****/
    private int  nowSecondPosition ;
    public ListRightAreaSecondAdapter(Context cnt, LinkedList<String> list, int nowSecondPosition){
        this.cnt = cnt;
        this.list = list;
        this.nowSecondPosition = nowSecondPosition;
        layoutInflater = LayoutInflater.from(cnt);
    }
    public void setMyNotifyDataChanged (LinkedList<String> list,int nowSecondPosition){
        this.list = list;
        this.nowSecondPosition = nowSecondPosition;
        notifyDataSetChanged();
    }
    @Override
    public int getCount() {
        return  list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = layoutInflater.inflate(R.layout.item_my_small_gv,null);
            viewHolder = new ViewHolder();
            viewHolder.tv_item_status_satified = (TextView) convertView.findViewById(R.id.tv_item_status_satified);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        String str =  list.get(position);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, DensityUtil.dip2px(cnt,45));
        //layoutParams.setMargins(10, 5, 10, 5);//4个参数按顺序分别是左上右下搜索
        viewHolder.tv_item_status_satified.setLayoutParams(layoutParams);
        viewHolder.tv_item_status_satified.setGravity(Gravity.CENTER);
        viewHolder.tv_item_status_satified .setText(str);
        viewHolder.tv_item_status_satified .setBackground(ContextCompat.getDrawable(cnt, R.drawable.selector_search_list_text_fan));
        // 默认选中的条目背景
        if (position == nowSecondPosition) {
            viewHolder.tv_item_status_satified .setSelected(true);
        } else {
            viewHolder.tv_item_status_satified .setSelected(false);
        }
        return convertView;
    }


    private class ViewHolder{
        private TextView tv_item_status_satified;
    }

}
